<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>多级作用域的嵌套</title>
</head>
<body>
    <script>
        let arr = [];
        for(let i = 0; i < 5; i++){
            arr.push(function(){
                return i;
            })
        };
        // 往arr数组中压入函数，不会将for的空间给销毁掉
        console.log(arr[1]());




        // 使用var
        let array = [];
        for (var j = 0; j < 5; j++) {
            (function(j){
                array.push(function(){
                    return j;
                })
            })(j);
        };
        console.log(array[0]());
    </script>
</body>
</html>